package sandbox.swing;

import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class GlassPanel extends JPanel {

    JLabel padding;
    JLabel title;
    JProgressBar waiter;

    public GlassPanel() {
        super(new GridLayout(0, 1));
        padding = new JLabel();
        waiter = new JProgressBar(0, 100);
        waiter.setIndeterminate(true);
        title = new JLabel("Please wait...");

        JPanel controlPane = new JPanel(new GridLayout(2, 1));
        controlPane.setOpaque(false);
        controlPane.add(title);
        controlPane.add(waiter);
        setOpaque(false);
        add(padding);
        add(new JLabel());
        add(controlPane);
        add(new JLabel());
        add(new JLabel());

        // trap both mouse and key events.  Could provide a smarter key handler
        // if you wanted to allow things like a keystroke that would cancel the
        // long-running operation.
        addMouseListener(new MouseAdapter() {
        });
        addMouseMotionListener(new MouseMotionAdapter() {
        });
        addKeyListener(new KeyAdapter() {
        });

        // make sure the focus won't leave the glass pane
        setFocusCycleRoot(true);  // 1.4
//        padding.setNextFocusableComponent(padding);  // 1.3
    }

    public void focus() {
        padding.requestFocus();
    }

    public void update(int progress) {
//        waiter.setValue(progress);
    }
}
